package edu.mtu.citizenscience.cs.notepad.activity;

import java.util.List;

import com.openswimsoftware.orm.model.list.ModelArrayList;

import edu.mtu.citizenscience.cs.notepad.NPListActivity;
import edu.mtu.citizenscience.cs.notepad.activity.noteslist.NoteActivity;
import edu.mtu.citizenscience.cs.notepad.activity.noteslist.NoteListAdapter;
import edu.mtu.citizenscience.cs.notepad.model.ModelNote;

import android.content.Intent;
import android.view.View;
import android.widget.ListView;
/**
 * @author Corbin Uselton <corbinu@cwuselto@mtu.edu>
 * @copyright (c) 2012 MichiganTech <http://www.mtu.edu>
 * @since 1.0
 * 
 * Main Notes List Activity Responsible for 
 * displaying the list of current notes
 */
public class NotesListActivity extends NPListActivity {
	// list of notes to display on the list view
	private List<ModelNote> notes;
	
	/**
	 * Main Activity resume handler
	 * 
	 * @param   void
	 * @return	void
	 */
	@Override
	public void onResume()
	{
		super.onResume();
		
		// find a list of all note models
		this.notes = new ModelArrayList<ModelNote>(this, ModelNote.class).find();
		
		// set the list adapter to a new note list adapter adding the note list
		this.setListAdapter(new NoteListAdapter(this.aq, this.notes));
	}
	
	/**
	 * onListItemClick hander for when one of the notes is clicked
	 * 
	 * @param   listView - ListView - The ListView where the click happened
	 * @param	view - View - The view that was clicked within the ListView
	 * @param	position - int - The position of the view in the list
	 * @param	id - long - The row id of the item that was clicked
	 * @return	void
	 */
	@Override
	public void onListItemClick(ListView listView, View view, int position, long id)
	{
		// get the note model of clicked item and get the id from the model
		long noteId = this.notes.get(position).getId();
		
		// launch the note activity passing the note id so it can be viewed
		this.startActivity(new Intent(this, NoteActivity.class).putExtra(ModelNote.NOTE_ID, noteId));
	}

}
